/*******************************************************************
 * 
 * @Version : 0.5 
 *
 * MonsterResourceManager.java 
 *
 * 2011-10-11 上午10:49:34
 *
 *******************************************************************/
package game.breeze.resource.manager;

import game.breeze.resource.MonsterDef;

import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;

import jxl.Sheet;
import jxl.Workbook;

/**
 * Class desc there
 * 
 * @author yangwei ywengineer@gmail.com
 * 
 */
public class MonsterResourceManager extends ResourceManager {
	private static final Logger logger = Logger.getLogger(MonsterResourceManager.class);
	private Map<Integer, MonsterDef> monsterDic = new HashMap<Integer, MonsterDef>();

	/**
	 * @param resource
	 */
	public MonsterResourceManager(String resource) {
		super(resource);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
	 */
	@Override
	public void afterPropertiesSet() throws Exception {
		Workbook workbook = Workbook.getWorkbook(resource);
		if (workbook == null) {
			logger.error("不存在怪物的配置数据");
			throw new Exception("不存在怪物的配置数据");
		}
		Sheet sheet = workbook.getSheet(0);
		int size = sheet.getRows();
		MonsterDef monster = null;
		for (int index = 1; index < size; index++) {
			monster = new MonsterDef(sheet.getRow(index));
			monsterDic.put(monster.getId(), monster);
		}
	}

	public MonsterDef findMonster(int id) {
		return monsterDic.get(id);
	}
}
